// Copyright (c) 2008 Matthew Johnson
// Licensed under the MIT License (see license.txt)
package actionml.animation {
	class ColorPropertyTweenRenderer extends PropertyTweenRenderer {
		protected var _startRed:Number;
		protected var _startGreen:Number;
		protected var _startBlue:Number;
		protected var _redDistance:Number;
		protected var _greenDistance:Number;
		protected var _blueDistance:Number;
		public static function isApplicable(targetClass:Class, property:String) {
			return property && property["contains"]("olor");
		}
		public function ColorPropertyTweenRenderer(target:Object, property:String, start:Number, end:Number, tween:Tween) {
			super(target, property, start, end, tween);
		}
		public override function prepareToRender() {
			super.prepareToRender();
			var end:Number = _renderStart + _renderDistance;
			_startRed = _renderStart >> 16;
			_redDistance = (end >> 16) - _startRed;
			_startGreen = (_renderStart >> 8) & 0xff;
			_greenDistance = ((end >> 8) & 0xff) - _startGreen;
			_startBlue = _renderStart & 0xff;
			_blueDistance = (end & 0xff) - _startBlue;
		}
		internal override function renderFrame(rc:RenderContext) {
			_target[_property] = 
				_tween.ease(rc.time - _tween.startTime, _startRed, _redDistance, _tween.renderDuration) << 16
				| _tween.ease(rc.time - _tween.startTime, _startGreen, _greenDistance, _tween.renderDuration) << 8
				| _tween.ease(rc.time - _tween.startTime, _startBlue, _blueDistance, _tween.renderDuration);
		}
	}
}